<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">知识库应用管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>知识库应用管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">知识库产品管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">

		<div class="row">
			<div class="col-lg-12">
				<div class="note note-danger">
					<h3 class="box-heading">Tips</h3>
					<p>
						数字资源统一交易系统需要设置对应的产品库与价格。
					</p>
				</div>
			</div>
		</div>
		 
		<div class="row mbl">
			<div class="col-lg-6">
				<div class="input-group input-group-sm mbs">
					<span class="input-group-btn"> <select id="queryParams"
						data-toggle="dropdown" class="btn btn-danger dropdown-toggle"
						style="width :100px;">
							<option value="nickname">产品名称</option>
					</select> </span> <input id="text"  type="text" placeholder="请输入关键词..."
						class="form-control" /> <span class="input-group-btn"><button
							type="button" data-toggle="dropdown" 
							class="btn btn-success dropdown-toggle" onclick="get()">搜索</button>
					</span>
				</div>
			</div>
					<button class="btn btn-sm btn-primary" onclick="addproduct(0)">新建产品库</button>
		</div>

		<div class="row mbl" id="data_list">

			<!-- start  	-->
	        <div class="col-md-6">
	            <div class="panel">
	                <div class="panel-body pan">
	                    <div class="profile">
	                        <div class="user-info">
	                            <div style="margin-bottom: -15px" class="row">
	                                <div class="col-xs-12 col-sm-7">
	                                    <h2><a href="#" title="点击可对产品库进行编辑和删除">精品资源库</a></h2>
	                                    <p><strong>产品价格:</strong> ￥10.00/篇</p>
	                                    <p><strong>优惠/折扣金额:</strong> ￥0.00/篇</p>
	                                    <p><strong>优惠/折扣范围:</strong> 2017-01-01 至 2017-02-31</p>
	                                    <p>
		                                    <strong class="mrs">知识库:</strong>
		                                    <span class="label label-green mrs">人物库</span>
		                                    <span class="label label-green mrs">机构库</span>
		                                    <span class="label label-green mrs">文献库</span>
	                                    </p>
	                                    <p>
	                                    	<strong>操作:</strong> 
	                                    	<button class="btn btn-sm btn-info" onclick="">编辑</button>
	                                    	<button class="btn btn-sm btn-primary" onclick="">删除</button>
	                                    	<button class="btn btn-sm btn-info" onclick="">提交</button>
	                                    	<button class="btn btn-sm btn-info" onclick="">启用</button>
	                                    	<button class="btn btn-sm btn-primary" onclick="">禁用</button>
	                                    </p>
	                                </div>
	                                <div class="col-xs-12 col-sm-5 text-center">
	                                    <figure><img src="images/ziyuanku.jpg" alt="" style="display: inline-block" class="img-responsive" />
	                                    </figure>
	                                </div>
	                            </div>
	                        </div>
	                        <div class="user-action">
	                            <div class="row text-center divider">
	                                <div class="col-xs-12 col-sm-6 emphasis">
	                                    <h2><strong>0</strong></h2>
	                                    <p><small>资源总数</small>
	                                    </p>
	                                    <button class="btn btn-yellow btn-block">资源详情</button>
	                                </div>
	                                <div class="col-xs-12 col-sm-6 emphasis">
	                                    <h2><strong>0</strong></h2>
	                                    <p><small>订购量</small>
	                                    </p>
	                                    <button class="btn btn-blue btn-block">订购详情</button>
	                                </div>
	                            </div>
	                        </div>
	                        
	                    </div>
	                </div>
	            </div>
	        </div>
       
			<div class="col-md-6">
	            <div class="panel">
	                <div class="panel-body pan">
	                    <div class="profile">
	                        <div class="user-info">
	                            <div style="margin-bottom: -15px" class="row">
	                                <div class="col-xs-12 col-sm-7">
	                                    <h2><a href="#" title="点击可对产品库进行编辑和删除">精品资源库</a></h2>
	                                    <p><strong>产品价格:</strong> ￥10.00/篇</p>
	                                    <p><strong>优惠/折扣金额:</strong> ￥0.00/篇</p>
	                                    <p><strong>优惠/折扣范围:</strong> 2017-01-01 至 2017-02-31</p>
	                                    <p>
		                                    <strong class="mrs">知识库:</strong>
		                                    <span class="label label-green mrs">人物库</span>
		                                    <span class="label label-green mrs">机构库</span>
		                                    <span class="label label-green mrs">文献库</span>
	                                    </p>
	                                    <p>
	                                    	<strong>操作:</strong> 
	                                    	<button class="btn btn-sm btn-info" onclick="">编辑</button>
	                                    	<button class="btn btn-sm btn-primary" onclick="">删除</button>
	                                    	<button class="btn btn-sm btn-info" onclick="">提交</button>
	                                    	<button class="btn btn-sm btn-info" onclick="">启用</button>
	                                    	<button class="btn btn-sm btn-primary" onclick="">禁用</button>
	                                    </p>
	                                </div>
	                                <div class="col-xs-12 col-sm-5 text-center">
	                                    <figure><img src="images/ziyuanku.jpg" alt="" style="display: inline-block" class="img-responsive" />
	                                    </figure>
	                                </div>
	                            </div>
	                        </div>
	                        <div class="user-action">
	                            <div class="row text-center divider">
	                                <div class="col-xs-12 col-sm-6 emphasis">
	                                    <h2><strong>0</strong></h2>
	                                    <p><small>资源总数</small>
	                                    </p>
	                                    <button class="btn btn-yellow btn-block">资源详情</button>
	                                </div>
	                                <div class="col-xs-12 col-sm-6 emphasis">
	                                    <h2><strong>0</strong></h2>
	                                    <p><small>订购量</small>
	                                    </p>
	                                    <button class="btn btn-blue btn-block">订购详情</button>
	                                </div>
	                            </div>
	                        </div>
	                        
	                    </div>
	                </div>
	            </div>
	        </div>
	        
	        <div class="col-md-6">
	            <div class="panel">
	                <div class="panel-body pan">
	                    <div class="profile">
	                        <div class="user-info">
	                            <div style="margin-bottom: -15px" class="row">
	                                <div class="col-xs-12 col-sm-7">
	                                    <h2><a href="#" title="点击可对产品库进行编辑和删除">精品资源库</a></h2>
	                                    <p><strong>产品价格:</strong> ￥10.00/篇</p>
	                                    <p><strong>优惠/折扣金额:</strong> ￥0.00/篇</p>
	                                    <p><strong>优惠/折扣范围:</strong> 2017-01-01 至 2017-02-31</p>
	                                    <p>
		                                    <strong class="mrs">知识库:</strong>
		                                    <span class="label label-green mrs">人物库</span>
		                                    <span class="label label-green mrs">机构库</span>
		                                    <span class="label label-green mrs">文献库</span>
	                                    </p>
	                                    <p>
	                                    	<strong>操作:</strong> 
	                                    	<button class="btn btn-sm btn-info" onclick="">编辑</button>
	                                    	<button class="btn btn-sm btn-primary" onclick="">删除</button>
	                                    	<button class="btn btn-sm btn-info" onclick="">提交</button>
	                                    	<button class="btn btn-sm btn-info" onclick="">启用</button>
	                                    	<button class="btn btn-sm btn-primary" onclick="">禁用</button>
	                                    </p>
	                                </div>
	                                <div class="col-xs-12 col-sm-5 text-center">
	                                    <figure><img src="images/ziyuanku.jpg" alt="" style="display: inline-block" class="img-responsive" />
	                                    </figure>
	                                </div>
	                            </div>
	                        </div>
	                        <div class="user-action">
	                            <div class="row text-center divider">
	                                <div class="col-xs-12 col-sm-6 emphasis">
	                                    <h2><strong>0</strong></h2>
	                                    <p><small>资源总数</small>
	                                    </p>
	                                    <button class="btn btn-yellow btn-block">资源详情</button>
	                                </div>
	                                <div class="col-xs-12 col-sm-6 emphasis">
	                                    <h2><strong>0</strong></h2>
	                                    <p><small>订购量</small>
	                                    </p>
	                                    <button class="btn btn-blue btn-block">订购详情</button>
	                                </div>
	                            </div>
	                        </div>
	                        
	                    </div>
	                </div>
	            </div>
	        </div>

			<!-- end -->
		</div>



	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var id;
	var curr;
	$(function() {
		getDataList(1);

	});
	function get() {

		getDataList(1);
	}

	function getlay() {
		return id;
	}
	function del(iid) {
		if (confirm("是否确认删除！！")) {
			$.ajax({
				type : "post",
				url : "./repositoryProductdel.do",
				data : {
					"id" : iid
				},
				dataType : "json",
				success : function(data) {
					if(data[0] == 0){
						get();
						layer.msg('删除成功！');
					}else{
						layer.msg('删除失败!与项目管理有关联无法删除，请先删除项目管理钟关联内容！');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	//启用-禁用
	function Commit(iid, submitid) {
		$.ajax({
			type : "post",
			url : "./repositoryProductsubmit.do",
			data : {
				"id" : iid,
				"submitid" : submitid
			},
			dataType : "json",
			success : function(data) {
				get();
				layer.msg('请求成功');
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function addproduct(lid) {

		id = lid;

		layer.open({
			type : 2,
			area : [ '800px', '660px' ],
			scrollbar : false,
			shadeClose : true,
			fix : true, //不固定
			title : '知识库产品管理',
			//maxmin : true,  
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "application_repository_product_add.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.Page();
			},
			cancel : function(index) {
			}

		});
	}
	function getDataList() {

		$.getJSON("listfindRepositoryProduct.do",{
							type : 1,
							text :$("#text").val()
						},
						function(res) {
							var contents = '';
							for ( var i = 0; i < res.length; i++) {
								var st = new Array();
								var kk = "";
								var str = res[i].classesIds;
								str = str.substring(0, str.length - 1);//去掉最后末位的逗号
								st = str.split(",");
								for (j = 0; j < st.length; j++) {
									kk += '<span class="label label-green mrs">'
											+ st[j] + '</span>';
								}
								var unitsList='';
								if(res[i].units == "pian"){
									unitsList = "篇";
								} else if(res[i].units == "ye"){
									unitsList = "页";
								} else if(res[i].units == "zi"){
									unitsList = "字";
								}
								var statussubmit;
								if (res[i].status == 0) {
									statussubmit = "启用";
								} 
								if (res[i].status == 1) {
									statussubmit = "禁用";
								} 
								var chargeType;
								if (res[i].chargeType == 0) {
									chargeType = "产品库计费";
								} 
								if (res[i].chargeType == 1) {
									chargeType = "固定单价计费";
								} 
							contents+='<div class="col-md-6">'
						            +'<div class="panel">'
						            +'<div class="panel-body pan">'
						            +'<div class="profile" style="display: block;">'
						            +'<div class="user-info" style="min-height: 256px;">'
						            +'<div style="margin-bottom: -15px" class="row">'
						            +'<div class="col-xs-12 col-sm-7">'
						            +'<h2><a href="JavaScript:addproduct('+res[i].id+');" title="点击可对产品库进行编辑和删除">'+res[i].name+'</a></h2>';
						            if(unitsList != null && unitsList !=''){
						            	contents+='<p><strong>产品价格:</strong>'+res[i].price.toFixed(2) +"/"+unitsList+'</p>';
						            }else{
						            	contents+='<p><strong>产品价格:</strong>'+res[i].price.toFixed(2)+'</p>';
						            }
						    contents+='<p><strong>计费类型:</strong>'+chargeType+'</p>';
						    		if(unitsList != null && unitsList !=''){
						            	contents+= '<p><strong>优惠/折扣后金额:</strong> ￥'+res[i].preferentialPrice.toFixed(2)+"/"+unitsList+'</p>';
						            }else{
						            	contents+='<p><strong>优惠/折扣后金额:</strong> ￥'+res[i].preferentialPrice.toFixed(2)+'</p>';
						            }
						          	if(res[i].preferentialDateStart != null && res[i].preferentialDateStart !='' && res[i].preferentialDateEnd !=null && res[i].preferentialDateEnd !=''){
						            	contents+='<p><strong>优惠/折扣范围:</strong>'+res[i].preferentialDateStart+"至"+res[i].preferentialDateEnd+'</p>';
						            }
						            if(res[i].preferentialDateStart != null && res[i].preferentialDateStart !=''){
						            	if( res[i].preferentialDateEnd ==null || res[i].preferentialDateEnd ==''){
						            		contents+='<p><strong>优惠/折扣范围:</strong>'+res[i].preferentialDateStart+"至 待定"+'</p>';
						            	}
						            }
						            if(res[i].preferentialDateStart == null || res[i].preferentialDateStart ==''){
						            	contents+='<p><strong>优惠/折扣范围:</strong></p>';
						            }
						    contents+='<p>'
							        +'<strong class="mrs">知识库:</strong>'
							        +kk
						            +'</p>'
						            +'<p>'
						            +'<strong>操作:</strong>'
						            +'<button class="btn btn-sm btn-info" style="margin-right:5px;" onclick="addproduct('+res[i].id+')">编辑</button>'
						            +'<button class="btn btn-sm btn-primary" style="margin-right:5px;" onclick="del('+res[i].id+')">删除</button>'
						            +'<button class="btn btn-sm btn-info" style="margin-right:5px;" onclick="">提交</button>'
						            +'<button class="btn btn-sm btn-info" style="margin-right:5px;" onclick="Commit('+ res[i].id+ ','+res[i].status+')">'+statussubmit+'</button>'
						            +'</p>'
						            +'</div>'
						            +'<div class="col-xs-12 col-sm-5 text-center">'
						            +'<figure><img src="'+ res[i].coverImg +'" alt="" style="display: inline-block;height: 210px;" width="305" class="img-responsive" />'
						            +'</figure>'
						            +'</div>'
						            +'</div>'
						            +'</div>'
						            +'<div class="user-action">'
						            +'<div class="row text-center divider">'
						            +'<div class="col-xs-12 col-sm-6 emphasis">'
						            +'<h2><strong>0</strong></h2>'
						            +'<p><small>资源总数</small>'
						            +'</p>'
						            +'<button class="btn btn-yellow btn-block">资源详情</button>'
						            +'</div>'
						            +'<div class="col-xs-12 col-sm-6 emphasis">'
						            +'<h2><strong>0</strong></h2>'
						            +'<p><small>订购量</small>'
						            +'</p>'
						            +'<button class="btn btn-blue btn-block">订购详情</button>'
						            +'</div>'
						            +'</div>'
						            +'</div>'
						            +'</div>'
						            +'</div>'
						            +'</div>'
						       		+'</div>'	
							}
							$("#data_list").html(contents);
						});

	};
</script>